package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.InventoryMapper;
import com.neu.mapper.SalesoutMapper;
import com.neu.po.Salesout;
import com.neu.po.SalesoutExample;
import com.neu.view.BigType;
@Service
public class SalesoutServiceImpl implements SalesoutService {

	@Autowired
	private SalesoutMapper salesoutMapper;
	@Autowired
	private InventoryMapper inventoryMapper;
	
	@Override
	public PageInfo<Salesout> getPaged(int pageNum, int pageSize, String keyword) {
		SalesoutExample example = new SalesoutExample();
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Salesout> list = salesoutMapper.selectByExample(example);
		
		PageInfo<Salesout> pageinfo = new PageInfo<>(list);
		
		return pageinfo;
	}
	@Override
	public int insert(Salesout salesout) {
		
		return salesoutMapper.insert(salesout);
	}
	
	@Override
	@Transactional
	public int insertUpdate(BigType bigtype) {
		int a = salesoutMapper.insert(bigtype.getSalesout());
		int b = inventoryMapper.updateByPrimaryKey(bigtype.getInventory());
		
		if(a == 1 && b == 1) {
			return 1;
		}
		
		
		return 0;
	}
	  

}
